package com.xcyy.zjdxmjk.zjdxmjk.controller;

import com.xcyy.zjdxmjk.zjdxmjk.VO.ResultVO;
import com.xcyy.zjdxmjk.zjdxmjk.common.ResultVOUtil;
import com.xcyy.zjdxmjk.zjdxmjk.entity.House;
import com.xcyy.zjdxmjk.zjdxmjk.service.HouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HouseController {
    @Autowired
    private HouseService houseService;

    @PostMapping("/addhouse")
    private ResultVO addHouse(House house) {

        House house1=houseService.findByDateAndStageAndTypeAndTownCode(house.getDate(),house.getStage(),house.getType(),house.getTownCode());
        House result ;
        if (house1==null){
            result = houseService.save(house);
        }else {
            house1.setCount(house.getCount());
            result=houseService.save(house1);
        }
        if (result == null) {
            return ResultVOUtil.error(400, "新增失败");
        }
        return ResultVOUtil.success(result);
    }
}
